package com.lz.sports.vm.score

import android.widget.Toast
import androidx.lifecycle.MutableLiveData
import com.lz.helper.idcard.IDCardInfo
import com.lz.library.base.BaseModel
import com.lz.library.base.BaseViewModel
import com.lz.sports.R
import com.lz.sports.bean.Examinee
import com.lz.sports.core.ProjectManager
import com.lz.sports.db.ExamineeDatabase
import com.lz.sports.utils.ToastUtils

//成绩确认
class ScoreSureViewModel : BaseViewModel<BaseModel>() {

    private val examPlanId = ProjectManager.examPlanId()
    //考区ID
    private val examAreaId = ProjectManager.examAreaId()
    //考点ID
    private val examSiteId = ProjectManager.examSiteId()

    //人脸识别时的身份证信息
    val idCardInfoData = MutableLiveData<IDCardInfo>()

    //注意此方法为耗时操作
    fun findExaminee(idCardInfo: IDCardInfo): Examinee? =
        ExamineeDatabase.get().examineeWithResultInspect(examPlanId, examAreaId, examSiteId, idCardInfo.num)

    fun findIdentifyExaminee(idCardInfo: IDCardInfo): Examinee? {
        idCardInfoData.postValue(idCardInfo)
        val examinee = ExamineeDatabase.get().examineeWithResultInspect(examPlanId, examAreaId, examSiteId, idCardInfo.num)
        if (examinee == null) {
            launch {
                ToastUtils.showMyToast(R.string.inspect_in_none, Toast.LENGTH_SHORT)
            }
        }
        return examinee
    }

}